//
//  FQDPlainSettingCell.m
//  FakeQDaily
//
//  Created by mewxiv on 9/9/16.
//  Copyright © 2016 Xensius. All rights reserved.
//

#import "FQDPlainSettingCell.h"
#import "FQDSettingOption.h"

#import "Masonry.h"

@interface FQDPlainSettingCell ()

@property (nonatomic, strong) UIImageView *revealImageView;
@property (nonatomic, strong) UIView *separateLine;

@end

@implementation FQDPlainSettingCell
@synthesize option = _option;

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:reuseIdentifier];
    if (self) {
        [self prepareUI];
        [self prepareConstraints];
    }
    return self;
}

- (void)prepareUI
{
    self.backgroundColor = [UIColor clearColor];
    self.textLabel.font = FQDRegularFontWithSize(17.0f);
    self.textLabel.textColor = [UIColor whiteColor];
    self.detailTextLabel.font = FQDRegularFontWithSize(16.0f);
    self.detailTextLabel.textColor = [UIColor colorWithWhite:0.7f alpha:1.0f];
    
    
    UIImage *revealImage = [UIImage imageNamed:@"go"];
    _revealImageView = [[UIImageView alloc] initWithImage:revealImage];
    [self addSubview:_revealImageView];
    self.accessoryView = _revealImageView;
    
    _separateLine = [[UIView alloc] init];
    _separateLine.backgroundColor = [UIColor colorWithWhite:1.0f alpha:0.2f];
    [self addSubview:_separateLine];
    
}

- (void)prepareConstraints
{
    WeakSelf;
    
    self.contentView.translatesAutoresizingMaskIntoConstraints = NO;
    [self.contentView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.top.left.and.right.equalTo(weakSelf);
//        make.bottom.equalTo(weakSelf.separateLine.mas_top);
        make.height.equalTo(@40.5);
    }];
    
//    [_revealImageView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.right.equalTo(weakSelf).offset(-15);
//        make.centerY.equalTo(weakSelf);
//    }];
    
    [_separateLine mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(weakSelf).offset(14);
        make.right.equalTo(weakSelf);
        make.bottom.equalTo(weakSelf);
        make.height.equalTo(@0.5);
    }];
}

- (void)setOption:(FQDSettingOption *)option
{
    _option = option;
    self.textLabel.text = option.title;
    self.detailTextLabel.text = option.detail;
    self.revealImageView.hidden = !option.hasMore;
    
    if (option.icon) {
        UIImage *iconImage = [UIImage imageNamed:option.icon];
        self.imageView.image = iconImage;
    }
}

+ (NSString *)reuseId
{
    return @"FQDplainSettingCell";
}

@end
